package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbContract;
import com.ruoyi.wb.dto.WbContractDto;
import com.ruoyi.wb.service.IWbContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 维保合同Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */

@Api(tags="维保合同管理")
@RestController
@Validated
@RequestMapping("/wb/wbContract")
public class WbContractController extends BaseController {
    @Autowired
    private IWbContractService wbContractService;

    /**
     * 查询维保合同列表
     */
    @ApiOperation("查询维保合同列表")
    @GetMapping("/list")
    public TableDataInfo list(WbContract wbContract) {
        startPage();
        List<WbContract> list = wbContractService.selectWbContractList(wbContract);
        return getDataTable(list);
    }

    /**
     * 导出维保合同列表
     */
    @ApiOperation("导出维保合同列表")
    @Log(title = "维保合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbContract wbContract) {
        List<WbContract> list = wbContractService.selectWbContractList(wbContract);
        ExcelUtil<WbContract> util = new ExcelUtil<WbContract>(WbContract.class);
        util.exportExcel(response, list, "维保合同数据");
    }

    /**
     * 获取维保合同详细信息
     */
    @ApiOperation("获取维保合同详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wbContractService.selectWbContractById(id));
    }

    /**
     * 新增维保合同
     */
    @ApiOperation("新增维保合同")
    @Log(title = "维保合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody WbContractDto wbContractDto) {
        return toAjax(wbContractService.insertWbContract(wbContractDto));
    }

    /**
     * 修改维保合同
     */
    @ApiOperation("修改维保合同")
    @Log(title = "维保合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbContract wbContract) {
        return toAjax(wbContractService.updateWbContract(wbContract));
    }

    /**
     * 删除维保合同
     */
    @ApiOperation("删除维保合同")
    @Log(title = "维保合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wbContractService.deleteWbContractByIds(ids));
    }
}